package zjc.bookkeeping.minepage.dAccountbookmanagement;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.cardview.widget.CardView;

import java.util.List;
import java.util.Map;

import zjc.bookkeeping.R;
import zjc.bookkeeping.db.AccountBean;
import zjc.bookkeeping.db.DBManager;
import zjc.bookkeeping.server.StaticData;

public class accountbookListAdapter extends BaseAdapter {
    Context context;
    List<AccountBean> accountBeanList;

    public accountbookListAdapter(Context context, List<AccountBean> accountBeanList) {
        this.context = context;
        this.accountBeanList = accountBeanList;
    }

    @Override
    public int getCount() {
        return accountBeanList.size();
    }

    @Override
    public Object getItem(int i) {
        return accountBeanList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        view = LayoutInflater.from(context).inflate(R.layout.activity_accountbook_item,viewGroup,false);
        TextView accountName = view.findViewById(R.id.acbookname);
        TextView outcome = view.findViewById(R.id.acbookout);
        TextView income = view.findViewById(R.id.acbookin);
        TextView kind = view.findViewById(R.id.acbookkind);
        TextView time = view.findViewById(R.id.acbooktime);
        TextView itme = view.findViewById(R.id.acbooknumber);
        CardView cardView = view.findViewById(R.id.account_card);
        accountName.setText(accountBeanList.get(i).getAccount_name());
        outcome.setText(accountBeanList.get(i).getAccount_outcome()+"");
        income.setText(accountBeanList.get(i).getAccount_income()+"");
        if (accountBeanList.get(i).getAccount_kind() == 1){
            kind.setText("多人");
        }
        time.setText(accountBeanList.get(i).getAccount_time());
        itme.setText(accountBeanList.get(i).getAccount_item()+"");
        if (DBManager.selectPos() == i){
            cardView.setBackgroundColor(context.getResources().getColor(R.color.blue_BDDCFC));
        }
        return view;
    }
    //删除数据，根据浮标
    public void remove(int i) {
        accountBeanList.remove(i);
        notifyDataSetChanged();
    }
}
